(function() {
	window.util=window.util||{};
	function factory(paramkeys) {
		this.paramkeys = paramkeys||[];
		this.funs = {};
		this.params = [];
	}
	factory.prototype = {
		preapareParam : function() {
			this.params = [];
			for (var i = 0; i < this.paramkeys.length; i++) {
				this.params.push(this[this.paramkeys[i]]);
			}
		},
		execute:function(key,extendParam,evl){
			this.preapareParam(this.paramkeys);
			if(key){
				if(typeof this.funs[key] =='function'){
					this.funs[key].apply(evl||this, this.params.concat(extendParam));
				}else{
					console.log("no function:",key);
				}
			}else{
				this.executeAll(evl);
			}
		},
		executeAll : function(evl) {
			this.preapareParam(this.paramkeys);
			for (p in this.funs) {
				//console.log(this.funs[p]);
				if(typeof this.funs[p]=='function'){
					this.funs[p].apply(evl||this, this.params);
				}
			}
		},
		add : function(fun, key) {
			key = key || fun.toString();
			this.funs[key] = fun;
		},
		get : function(key) {
			key = key.toString();
			return this.funs[key];
		},
		addWithExecute : function(fun, key) {
			key = key || fun.toString();
			this.funs[key] = fun;
			this.funs[key](this.user);
		},
		remove : function(key) {
			key = key.toString();
			delete this.funs[key];
		}
	};
	window.util.factory=factory;
})();